
#ifndef __SDK_QUEUE__INCLUDE__
#define __SDK_QUEUE__INCLUDE__

#include "Utility/ErrorCode.h"

namespace nebula { namespace sdk {

class ITask;
class IService;

typedef bool (*TaskFilter)(IService*, const char*, const ITask*);

class IDoneTaskQueue
{
public:
	virtual ~IDoneTaskQueue(){};

public:
	//Add a task to the queue and this also means that the caller
	// loses the ownership of the task
	virtual NEBULA_ERROR_CODE AddTask (ITask* task) = 0;

	//Equip a filter for the frameworks to determine whether a task
	// should be returned when a pop request is coming.
	// pass a null pointer to indicate the behavior of no filter
	// the prototype of the filter is:
	//	bool TaskFilter(IService* service, const char* target_node_name, const ITask* task);
	virtual NEBULA_ERROR_CODE SetFilter(TaskFilter) = 0;

	//Get the size (length) of the queue
	virtual unsigned long GetSize() = 0;

	//Get the traffic (the amount of tasks which have been transferred
	// during the just past 60 seconds) of the queue
	virtual unsigned long GetTraffic() = 0;
};

class ITodoTaskQueue
{
public:
	virtual ~ITodoTaskQueue() {};

public:
	//Pick a task from queue. The caller now owned the task and responsible for
	// the deletion of the task. Return NULL pointer if no task in queue or
	// there is an error, or time out
	virtual ITask* GetTask(bool blocking=true, unsigned timeout=0xFFFFFFFF) = 0;

	//Raise a notification that a task is done
	virtual NEBULA_ERROR_CODE TaskDone() = 0;

	//Get the size (length) of the queue
	virtual unsigned long GetSize() = 0;

	//Get the traffic (the amount of tasks which have been fetched via GetTask
	// during the just past 60 seconds) of the queue
	virtual unsigned long GetTraffic() = 0;
};

}} //end of nebula::sdk

#endif //__SDK_QUEUE__INCLUDE__
